// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'lib-flexible'
import vuex from 'vuex'
import store from './store'
import VueBetterCalendar from 'vue-better-calendar'
import filters from './tool/filters'
import uniquePay from 'unique-pay'
// import vconsole from './tool/vconsole'
import VWechatAuth from 'v-wechat-auth'
import axios from './axios'
import * as API from './api'
import { LoadingPlugin } from 'vux'
Vue.use(LoadingPlugin)
Vue.use(uniquePay, {
  useSdk: false // 是否使用各自平台 jssdk
})

Vue.prototype.$http = axios
for (let key in filters) {
  Vue.filter(key, filters[key])
}
Vue.config.productionTip = false
Vue.use(vuex)
Vue.use(VueBetterCalendar)
Vue.use(VWechatAuth)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>',
  wechatAuth: new VWechatAuth({
    appId: 'wx245ef3e0e4c9c9a4',
    scope: 'snsapi_userinfo',
    authorize(code) {
      console.log(code)
      axios
        .get(API.login, {
          params: {
            code: code
          }
        })
        .then(res => {
          console.log(res.data)
          localStorage.setItem('token', 'isLogin')
          store.dispatch('initUser', res.data)
        })
        .catch(err => {
          console.log(err)
          localStorage.clear()
        })
    }
  })
})
